package com.ict.web.dto;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ict.common.annotation.Excel;
import com.ict.common.utils.StringUtils;
import com.ict.common.utils.bean.BeanUtils;
import com.ict.common.utils.uuid.IdUtils;
import com.ict.web.controller.file.domain.YzqFile;
import com.ict.web.controller.file.dto.YzqFileDTO;
import com.ict.web.domain.AnnualDeclaration;
import com.ict.web.domain.ContractInformation;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;

@Data
public class ContractInformationAddDto {

    /**
     * 项目id
     */
    @ApiModelProperty(value = "项目id")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    @NotNull(message = "项目id不能为空")
    private Long proId;

    /**
     * 合同名称
     */
    @Excel(name = "合同名称")
    @ApiModelProperty(value = "合同名称")
    private String contractName;

    /**
     * 合同编号
     */
    @Excel(name = "合同编号")
    @ApiModelProperty(value = "合同编号")
    private String contractNo;

    /**
     * 合同金额
     */
    @Excel(name = "合同金额")
    @ApiModelProperty(value = "合同金额")
    @NotNull(message = "合同金额不能为空")
    private BigDecimal contractAmount;

    /**
     * 签约时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @ApiModelProperty(value = "签约时间")
    @Excel(name = "签约时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date signingTime;

    /**
     * 合同扫描件（有公章）
     */
    @Excel(name = "合同扫描件", readConverterExp = "有=公章")
    @ApiModelProperty(value = "合同扫描件（有公章）")
    private YzqFileDTO scannedCopyOfContract;

    /**
     * 招标公告网址
     */
    @Excel(name = "招标公告网址")
    @ApiModelProperty(value = "招标公告网址")
    private String tenderAnnouncementWebsite;

    /**
     * 招标公告文件
     */
    @Excel(name = "招标公告文件")
    @ApiModelProperty(value = "招标公告文件")
    private YzqFileDTO tenderAnnouncementFile;

    /**
     * 中标公告网址
     */
    @Excel(name = "中标公告网址")
    @ApiModelProperty(value = "中标公告网址")
    private String websiteOfBidWinningAnnouncement;

    /**
     * 中标公告文件
     */
    @Excel(name = "中标公告文件")
    @ApiModelProperty(value = "中标公告文件")
    private YzqFileDTO bidWinningAnnouncementFile;

    /**
     * 甲方
     */
    @Excel(name = "甲方")
    @ApiModelProperty(value = "甲方")
    private String partyA;

    /**
     * 甲方联系人
     */
    @Excel(name = "甲方联系人")
    @ApiModelProperty(value = "甲方联系人")
    private String contactPersonA;

    /**
     * 甲方联系电话
     */
    @Excel(name = "甲方联系电话")
    @ApiModelProperty(value = "甲方联系电话")
    private String contactNumberA;

    /**
     * 乙方
     */
    @Excel(name = "乙方")
    @ApiModelProperty(value = "乙方")
    private String partyB;


    /**
     * 乙方联系人
     */
    @Excel(name = "乙方联系人")
    @ApiModelProperty(value = "乙方联系人")
    private String contactPersonB;

    /**
     * 乙方联系电话
     */
    @Excel(name = "乙方联系电话")
    @ApiModelProperty(value = "乙方联系电话")
    private String contactNumberB;

    /**
     * 将 ContractInformationAddDto 转化为 ContractInformation
     *
     * @param dto 接收dto
     * @return ContractInformation
     */
    public static ContractInformation of(ContractInformationAddDto dto) {
        ContractInformation bean = new ContractInformation();
        BeanUtils.copyProperties(dto, bean);

        //设置ID
        bean.setContractId(IdUtils.snowId());
        //设置创建时间
        bean.setCreateTime(LocalDateTime.now());
        //设置创建时间
        bean.setUpdateTime(LocalDateTime.now());
        //设置物理删除标记
        bean.setDelFlag("0");

        return bean;
    }

    /**
     * 将 ContractInformationAddDto中需传文件对象 转化为 file
     *
     * @param dto 接收dto
     * @return HotelInfo
     */
    public static ArrayList<YzqFile> toFile(ContractInformation contractInformation, ContractInformationAddDto dto) {
        ArrayList<YzqFile> fileList = new ArrayList<>();
        YzqFileDTO scannedCopyOfContract = dto.getScannedCopyOfContract();
        YzqFileDTO tenderAnnouncementFile = dto.getTenderAnnouncementFile();
        YzqFileDTO bidWinningAnnouncementFile = dto.getBidWinningAnnouncementFile();

        if (StringUtils.isNotNull(scannedCopyOfContract)) {
            YzqFile fileScoc = new YzqFile();
            fileScoc.setId(String.valueOf(IdUtils.snowId()));
            BeanUtils.copyProperties(scannedCopyOfContract, fileScoc);
            fileList.add(fileScoc);
            contractInformation.setScannedCopyOfContract(fileScoc.getId());
        }

        if (StringUtils.isNotNull(tenderAnnouncementFile)) {
            YzqFile fileTaf = new YzqFile();
            fileTaf.setId(String.valueOf(IdUtils.snowId()));
            BeanUtils.copyProperties(tenderAnnouncementFile, fileTaf);
            fileList.add(fileTaf);
            contractInformation.setTenderAnnouncementFileId(fileTaf.getId());
        }

        if (StringUtils.isNotNull(bidWinningAnnouncementFile)) {
            YzqFile fileBwa = new YzqFile();
            fileBwa.setId(String.valueOf(IdUtils.snowId()));
            BeanUtils.copyProperties(bidWinningAnnouncementFile, fileBwa);
            fileList.add(fileBwa);
            contractInformation.setBidWinningAnnouncementFileId(fileBwa.getId());
        }
        return fileList;
    }
}
